<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />
</head>
<body  class="fixed-header theme-blue-gradient">
<div   id="theme-wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />

    <div id="page-wrapper" class="container">
        <div class="row">
            <include file="./Application/Home/View/Tpl/menu.html"/>

            <div id="content-wrapper">
                <BR>
                <div class="row">
                    <include file="./Application/Home/View/Tpl/alert.html"/>

                    <div class="row">
                        <div class="focusPersonWrap">
                            <div class="panel">
                                <div class="panel-heading">
		                            	<span class="panel-icon">
			                              	<i class="imoon imoon-table2"></i>
			                            </span>
                                    <span class="panel-title">取证下发列表</span>
                                    <div class="widget-menu pull-right mr10" data-step="1" data-intro="点击按钮，可下发取证文件" data-position='right'>
                                        <div class="btn-group">
                                            <a href="#" data-toggle="modal" data-target="#modal-addTroy" class="btn btn-sm  btn-success btnaddTroy"><i class="glyphicon glyphicon-plus"></i>下发取证文件</a>
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-body pn">
                                    <div class="deviceList admin-form">
                                        <table id="troypushTable" class="table table-striped table-bordered" cellspacing="0" width="100%" data-step="3" data-position='top'>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <include file="./Application/Home/View/Tpl/footer.html"/>

            </div>
        </div>

    </div>



    <!--下发取证文件    start-->
    <div class="modal fade bs-example-modal-lg" id="modal-addTroy" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <form id="addTroy"  class="form-horizontal form-bordered">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">下发取证</h4>
                    </div>
                    <div class="modal-body">
                        <div class="admin-form clearfix">

                            <div class="section mb10 col-md-12">
                                <label for="stamac" class="field-label text-center pull-left lh40">查找终端mac：</label>
                                <div class="col-md-10">
                                    <label for="stamac" class="field">
                                        <select id="stamac" name="stamac" class="select-chosen" data-placeholder="选择终端..." style="width: 480px;">
                                            <option></option><!-- Required for data-placeholder attribute to work with Chosen plugin -->
                                            <foreach name="stamac" item="vo">
                                                <option  value="{$vo.s_mac}">{$vo.s_mac}(捕获时间:{$vo.time|substr=0,4}年{$vo.time|substr=4,2}月{$vo.time|substr=6,2}日
                                                    {$vo.time|substr=8,2}:{$vo.time|substr=10,2}:{$vo.time|substr=12,2})</option>
                                            </foreach>
                                        </select>
                                    </label>
                                </div>
                            </div>

                            <div class="section mb10 col-md-12">
                                <label for="troyname" class="field-label text-center pull-left lh40" >选择取证文件：</label>
                                <div class="col-md-10">
                                    <label for="troyname" class="field">
                                        <select id="troyname" name="troyname" class="select-chosen" data-placeholder="选择取证文件..." style="width: 480px;">
                                            <option></option><!-- Required for data-placeholder attribute to work with Chosen plugin -->
                                            <foreach name="troylist" item="vo">
                                                <option troyfile="{$vo.troyfile}" troyfiledesc="{$vo.troydesc}" value="{$vo.troyname}">{$vo.troyname}(版本号:{$vo.troyversion})</option>
                                            </foreach>
                                        </select>
                                    </label>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">下发取证</button>
                    </div>
                </div><!-- /.modal-content -->
                <input type="hidden" id="deviceserialno" name="deviceserialno" value="">
            </form>
        </div><!-- /.modal-dialog -->
    </div><!--下发取证    end-->




</div>
<!-- ./wrapper -->

<include file="./Application/Home/View/Tpl/commjs.html" />

<script src="__PUBLIC__/js/modernizr.js"></script>
<script src="__PUBLIC__/datatable/datatables.min.js"></script>
<script src="__PUBLIC__/datatable/dataTables.bootstrap.js"></script>
<script src="__PUBLIC__/plugins/confirm/confirm.js"></script>
<!-- PNotify -->
<script src="__PUBLIC__/plugins/pnotify/pnotify.js"></script>

<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/Chosen/css/chosen.css"/>
<script src="__PUBLIC__/plugins/Chosen/chosen.jquery.js"></script>

<script>
    $(document).ready(function () {
        $('.select-chosen').chosen( );



        getAllTroy();
        //操作提示信息
        function Msg(flag,text){
            if(flag){
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'success',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }else{
                new PNotify({
                    title: '提示信息',
                    text: text,
                    shadow: true,
                    opacity: 1,
                    addclass: 'stack_top_right',
                    type: 'danger',
                    stack: {
                        "dir1": "down",
                        "dir2": "left",
                        "push": "top",
                        "spacing1": 10,
                        "spacing2": 10
                    },
                    width: '400px',
                    delay: 3000
                });
            }
        }

        function getAllTroy(){
            var table = $('#troypushTable').DataTable({
                serverSide: true,
                "ajax": {
                    "url": "{:U('/Home/TrojansImplants/getTroyPushList','',false)}",
                    "type":"post",
                    "dataSrc": function ( d ) {
                        return d.data;
                    }
                },
                ordering: false,
                "bDestroy": true,
                bLengthChange: false,
                "bAutoWidth": false,
                "pagingType": "scrolling",
                "bInfo": false,
                paging: true,
                pageLength: 10,
                language: {
                    search: '<span class="label bg-primary" data-step="2" data-position="right" style="background-color: #5ccdde !important;padding:4px;">搜索</span>',//右上角的搜索文本，可以写html标签
                    paginate: {
                        previous: "上一页",
                        next: "下一页",
                        first: "首页",
                        last: "尾页"
                    },
                    zeroRecords: "没有内容",
                    infoEmpty: "0条记录",
                },
                pagingType: "full_numbers",//分页样式的类型devicemac
                "aoColumns": [
                    { "sTitle":"终端MAC", "data": "stamac"},

                    {"sTitle":"取证名称","data":"troyname"},
                    { "sTitle":"取证描述", "data":"troyfiledesc"},
                    {"sTitle":"下发时间","data":"pushtime"},
                    {"sTitle":"下发状态","data":"status"},
                    {"sTitle":"失败描述","data":"info"},
                    {"sTitle":"操作","data":null}

                ],
                "aoColumnDefs":[
                    {
                        "aTargets": 0,
                        "mRender": function (data, type,row) {
                            return '<span  myid="'+row.id+'">'+row.stamac+'</span>';
                        }
                    },{
                        "aTargets": 4,
                        "mRender": function (data, type,row) {
                            if(row.status==1){
                                return '<span  class="label label-danger">下发失败</span>';
                            }
                            return '<span  class="label label-success">下发成功</span>';
                        }
                    },
                    {
                        "aTargets": 6,
                        "mRender": function (data, type,row) {
                            return '<a href="#" class="btndelTrojans glyphicon glyphicon-trash ml5 btn btn-danger btn-xs"></a>'

                        }
                    }
                ],
                "fnDrawCallback": function ( oSettings ) {
                    $('.btndelTrojans').on('click',function(){
                        //获取该行
                        var row = $(this).parent().parent();
                        var id = $(this).parent().parent().children().first().children('span').attr('myid');

                        delTroy(id,row);
                    });
                    $('#modal-addTroy').on('shown.bs.modal', function () {
                        $('input').val('');
                    });
                }
            });
        }
        //删除取证文件
        function delTroy(troyid,row){
            Confirm.show('提示信息', '确定要删除吗？', {
                '删除': {
                    'primary': true,
                    'callback': function() {
                        Confirm.hide();
                        $.ajax({
                            url: "{:U('/Home/TrojansImplants/delTroyPushByNo','',false)}",
                            type: "post",
                            dataType: "json",
                            data:{"id":troyid},
                            success:function(result){
                                row.remove();
                                var flag = result.data;
                                var text = flag?'删除取证下发记录成功':'删除取证下发记录失败';
                                Msg(flag,text);
                            },
                            error: function (msg) {
                                //console.log(msg);
                            }
                        })
                    }
                }
            });

        }


        //下发取证文件
        $("#addTroy").validate({
            ignore: "",
            rules:{
                stamac:{
                    required:true,
                    maxlength:20
                },
                troyname:{
                    required:true
                }
            },
            messages: {
                stamac: {
                    required:'请选择待植取证终端mac地址'
                },
                troyname: {
                    required:'请选择取证文件'
                }
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent());
            },
            submitHandler: function(form) {  //通过之后回调
                var param = {
                    stamac: $("#stamac").val(),
                    troyname: $("#troyname").val(),
                    troyfile:$("#troyname").find("option:selected").attr('troyfile'),
                    troyfiledesc:$("#troyname").find("option:selected").attr('troyfiledesc')
                };

                $.ajax({
                    url: "{:U('/Home/TrojansImplants/pushTroy','',false)}",
                    type: "post",
                    dataType: "json",
                    data: param,
                    success: function (result) {
                        var flag = result.status;
                        flag?$("#modal-addTroy").modal('hide'):"";
                        var text = flag?'下发取证文件成功':'下发取证文件失败：'+result.info;
                        Msg(flag,text);
                        if(flag){
                            setTimeout(function () {
                                window.location.reload();
                            },1000)
                        }
                    },
                    error: function (msg) {
                        //console.log(msg);
                    }
                });

            },
            invalidHandler: function(form, validator) {  //不通过回调
                return false;
            }
        });
    })
</script>

</body>
</html>


